// 挂载
const Koa = require('koa');
const app = new Koa;

// 挂载
const router = require('koa-router')()
app.use(router.routes())
app.use(router.allowedMethods())

// 挂载
const json = require('koa-json')
const bodyparser = require('koa-bodyparser')
app.use(json())
app.use(bodyparser())

//引入路由文件
const banner = require('./router/index')

//注册路由中间件
app.use(banner.routes(), banner.allowedMethods())

// 挂载
const swagger = require('./swagger')  // 存放swagger.js的位置，可以自行配置，我放在了根目录
const { koaSwagger } = require('koa2-swagger-ui')

// 接口文档配置
app.use(swagger.routes(), swagger.allowedMethods())
app.use(koaSwagger({
  routePrefix: '/swagger', // 接口文档访问地址
  swaggerOptions: {
    url: '/swagger.json', // example path to json 其实就是之后swagger-jsdoc生成的文档地址
  }
}))

// 挂载
// const compressImage = require('./utils/picture');
// app.use(compressImage)
// 挂载
const mysql = require('mysql')

var coonnection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: '253547',
  database: 'node'
})

coonnection.connect(function (err) {
  if (err) {
    console.log("连接失败" + err.stack)
    return;
  }
  console.log("连接成功" + coonnection.threadId)
})

// 3000 端口号
app.listen(3000)
console.log('http://localhost:3000/');



